/*
MyOpenLab by Carmelo Salafia www.myopenlab.de
Copyright (C) 2004  Carmelo Salafia cswi@gmx.de

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package MyGraph;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

/**
 *
 * @author  Homer
 */
public class GraphBackground extends javax.swing.JPanel
{
    private double stepX=2;
    private double stepY=2;
    
    public double minX=0;
    public double maxX=100;
    public double minY=00;
    public double maxY=100;
    
    private boolean backgroundTransparent=false;

    
    public boolean getBackgroundTransparent()
    {
        return backgroundTransparent;
    }
    public void setBackgroundTransparent(boolean value)
    {
        backgroundTransparent=value;
    }
        
    
    /** Creates new form GraphBackground */
    public GraphBackground()
    {
        initComponents();
        setBackground(new Color(0,80,0));
    }
    
    public void setStepXInProzent(double stepXInProzent)
    {        
        stepX=((double)getWidth()*stepXInProzent)/100.0;
    }
    
    public void setStepYInProzent(double stepYInProzent)
    {        
        stepY=((double)getHeight()*stepYInProzent)/100.0;
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents()
    {
        jLabel1 = new javax.swing.JLabel();

        setLayout(null);

        addMouseMotionListener(new java.awt.event.MouseMotionAdapter()
        {
            public void mouseMoved(java.awt.event.MouseEvent evt)
            {
                formMouseMoved(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Arial", 0, 10));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setPreferredSize(new java.awt.Dimension(0, 20));
        add(jLabel1);
        jLabel1.setBounds(10, 0, 0, 20);

    }// </editor-fold>//GEN-END:initComponents

    private void formMouseMoved(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseMoved
    {//GEN-HEADEREND:event_formMouseMoved
        
    }//GEN-LAST:event_formMouseMoved
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

    public Color colorGrid= new Color(0,120,0);
    public Color colorSubGrid= new Color(0,90,0);
    
    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);   
        
        if (backgroundTransparent==false)
        {
            g.setColor(getBackground());
            g.fillRect(0,0,getWidth(),getHeight());
        
            double step=(stepX*20)/100;
            double step2=(stepY*20)/100;


            g.setColor(colorSubGrid);
            for (double v=0;v<(double)getWidth();v+=stepX)
            {          
              for (double c=0;c<(double)stepX;c+=step)
              {              
                g.drawLine((int)(v+c),0,(int)(v+c),getHeight());
              }
            }

            for (double v=0;v<(double)getHeight();v+=stepY)
            {         
              for (double c=0;c<(double)stepY;c+=step2)
              {              
                g.drawLine(0,(int)(v+c),getWidth(),(int)(v+c));
              }
            }

            g.setColor(colorGrid);
            for (double v=0;v<(double)getWidth();v+=stepX)
            {          
              g.drawLine((int)v,0,(int)v,getHeight());
            }

            for (double v=0;v<(double)getHeight();v+=stepY)
            {          
              g.drawLine(0,(int)v,getWidth(),(int)v);
            }
            
        }
    }
    

    
}
